package com.first.community.dto;

import com.first.community.exception.CustomizeErrorCode;
import com.first.community.exception.CustomizeExcetpion;
import lombok.Data;

@Data
public class ResultDTO<T> {

    private  Integer code;

    private  String message;

    private  T data;

    public static ResultDTO errorOf(Integer code,String message){

        ResultDTO resultDTO = new ResultDTO();
        resultDTO.setCode(code);
        resultDTO.setMessage(message);
        return resultDTO;
    }


    public static ResultDTO errorOf(CustomizeErrorCode code) {
        return  errorOf(code.getCode(),code.getMessage());
    }

    public static ResultDTO okof(CustomizeErrorCode success) {
        ResultDTO resultDTO = new ResultDTO();
        resultDTO.setCode(success.getCode());
        resultDTO.setMessage(success.getMessage());
        return resultDTO;
    }
    public static <T> ResultDTO okof(T t){
        ResultDTO resultDTO = new ResultDTO();
        resultDTO.setCode(200);
        resultDTO.setMessage("请求成功");
        resultDTO.setData(t);
        return  resultDTO;
    }


    public static ResultDTO errorOf(CustomizeExcetpion ex) {
        return  errorOf(ex.getCode(),ex.getMessage());
    }
}